package com.example.demo.util;

import com.example.demo.mapper.CustomerMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * 创建人： dutu
 * 时  间： 2018-01-02.
 */
public class TimeUtil {

    @Autowired
    private CustomerMapper customerMapper;
    public boolean utilTime(String time){
//        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());


        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss");
        LocalDateTime localTime = LocalDateTime.parse(time, dtf);
        LocalDateTime startTime = LocalDate.now().atTime(6, 0, 0);
        LocalDateTime endTime = LocalDate.now().atTime(22, 59, 59);
//        //如果小于今天的开始日期
//        if (localTime.isBefore(startTime)) {
//            System.out.println("不再时间范围");
//        }
        //如果大于今天的开始日期，小于今天的结束日期
        if (localTime.isAfter(startTime) && localTime.isBefore(endTime)) {
            System.out.println("在时间范围");
            return true;
        }else {
            System.out.println("不在时间范围");
            return false;
        }
//        //如果大于今天的结束日期
//        if (localTime.isAfter(endTime)) {
//            System.out.println("时间是未来");
//        }

    }

//    public Double selAmount(){
//        boolean b = false;
//        boolean flag = true;
//        double t = 0;
//        DecimalFormat df = new DecimalFormat("######0.00");
//
//
//        //查询数据库内规定时间内的金额
//        List<Double> list = customerMapper.getAmount();
//        int index = list.size();
//
//
////        for ( int i = 0; i < 1000;i++ )
////        {
////            Random r = new Random();
////            t = 299-Double.parseDouble(df.format(r.nextFloat()))-r.nextInt(5);
//////            if(t==298.88){
//////                b = true;
//////            }
////            for(int k = 0;k < index; k++){
////                if(t==list.get(k)){
////                    flag = false;
////                    break;
////                }
////            }
////            if(flag){
////                System.out.println ("--------------------"+t);
////            }
////            System.out.print (i+"--");
////            while (b){
////                i=1002;
////                System.out.print  ("------------结束取值---------------");
////                b=false;
////            }
//
////        }
////        return t;
//    }

}
